package com.ibeeking.found.org.b.rest.controller.v1;

import com.ibeeking.found.common.enums.PublishStatusEnum;
import com.ibeeking.found.org.b.rest.service.IDepartmentService;
import com.ibeeking.found.org.service.common.param.DepartmentParam;
import com.ibeeking.found.org.service.common.query.DepartmentQuery;
import com.ibeeking.found.org.service.common.vo.DepartmentTreeVO;
import com.ibeeking.found.org.service.common.vo.DepartmentVO;
import com.ibeeking.nematos.constants.enums.OperateLogTypeEnum;
import com.ibeeking.nematos.log.annotation.Log;
import com.ibeeking.nematos.utils.base.BaseValidationGroup;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName DepartmentController
 * @Description
 * @Author ibeeking
 * @Date 2021-01-29 14:48
 **/
@RestController
@RequestMapping("/b/department/v1")
public class DepartmentController {

    @Resource
    private IDepartmentService departmentServiceImpl;

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "部门列表")
    @PostMapping(value = "/list")
    public List<DepartmentVO> list(@RequestBody DepartmentQuery query) {
        return departmentServiceImpl.list(query);
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "部门树列表")
    @PostMapping(value = "/listTree")
    public List<DepartmentTreeVO> listTree(@RequestBody DepartmentQuery query) {
        query.setPublishStatus(null);
        return departmentServiceImpl.listTree(query);
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "有效部门树列表")
    @PostMapping(value = "/listEffectTree")
    public List<DepartmentTreeVO> listEffectTree(@RequestBody DepartmentQuery query) {
        query.setPublishStatus(PublishStatusEnum.ENABLE.getValue());
        return departmentServiceImpl.listTree(query);
    }

    @Log(logType = OperateLogTypeEnum.SAVE, describe = "部门添加")
    @PostMapping(value = "/add")
    public Boolean add(@RequestBody @Validated(BaseValidationGroup.Insert.class) DepartmentParam DepartmentParam) {
        return departmentServiceImpl.add(DepartmentParam);
    }

    @Log(logType = OperateLogTypeEnum.MODIFY, describe = "部门修改")
    @PostMapping(value = "/modify")
    public Boolean modify(@RequestBody @Validated(BaseValidationGroup.Update.class) DepartmentParam DepartmentParam) {
        return departmentServiceImpl.modify(DepartmentParam);
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "部门查看")
    @GetMapping(value = "/view/{id}")
    public DepartmentVO view(@PathVariable("id") Long id) {
        return departmentServiceImpl.view(id);
    }

    @Log(logType = OperateLogTypeEnum.MODIFY, describe = "部门状态修改")
    @GetMapping(value = "/changeStatus/{id}/{status}")
    public Boolean changeStatus(@PathVariable("id") Long id, @PathVariable("status") Integer status) {
        return departmentServiceImpl.changeStatus(id, status);
    }

    @Log(logType = OperateLogTypeEnum.DEL, describe = "部门删除")
    @GetMapping(value = "/del/{id}")
    public Boolean del(@PathVariable("id") Long id) {
        return departmentServiceImpl.del(id);
    }
}